﻿import QtQuick 2.0

import QtQuick.Controls 1.2

Rectangle{
    width: 320;
    height: 240;
    color: "gray";

    QtObject{
        id: attrs;
        property int counter;
        Component.onCompleted: attrs.counter = 10;
    }

    Text{
        id:countShow;
        anchors.centerIn: parent;
        color:"blue";
        font.pixelSize: 40;

    }

    Timer{
        id:countDown;
        interval: 1000; //1s 一次
        repeat: true; //周期性触发
        triggeredOnStart: true; //开始执行定时器的时候先触发一次
        onTriggered: {
            countShow.text = attrs.counter;

            attrs.counter -= 1;

            if(attrs.counter < 0){
                countDown.stop();
                countShow.text = "clap Now";
            }
        }
    }

    Button{
        id: startButton;
        anchors.top: countShow.bottom;
        anchors.topMargin: 20;
        anchors.horizontalCenter:  countShow.horizontalCenter;
        text:"start";
        onClicked: {

            attrs.counter = 10;
            countDown.start();
        }

    }
}

